home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / gemfut15.lzh / AESUTRC3.C < prev    next >
C/C++ Source or Header  |  1989-08-26  |  2KB  |  65 lines

  1.  
  2. /**************************************************************************
  3.  *
  4.  * AESFAST PD utilties.
  5.  *
  6.  *  Rectangle utilities 2...
  7.  *    rc_union
  8.  *************************************************************************/
  9.  
  10. #include <gemfast.h>
  11.  
  12. /*-------------------------------------------------------------------------
  13.  * rc_union - Compute union of 2 GRECT rectangles.
  14.  *            Does not return anything, since by definition the two
  15.  *            rectangles will have common area.
  16.  *
  17.  *  (Note that this code is virtually identical to rc_intersect, except
  18.  *   the direction of the comparison operators is reversed.)
  19.  *-----------------------------------------------------------------------*/
  20.  
  21. void
  22. rc_union(prect1, prect2)
  23.     register GRECT *prect1;
  24.     register GRECT *prect2;
  25. {
  26.     register int    w1, w2;
  27.     int             lx, rx;
  28.     int             ty, by;
  29.     
  30.     /* calc right-side x as the greater x of the two rectangles */
  31.      
  32.     w1 = prect1->g_x + prect2->g_w;
  33.     w2 = prect2->g_x + prect2->g_w;
  34.     rx  = (w1 > w2) ? w1 : w2;
  35.  
  36.     /*  calc bottom y as the greater y of the two rectanlges */
  37.  
  38.     w1 = prect1->g_y + prect1->g_h;
  39.     w2 = prect2->g_y + prect2->g_h;
  40.     by  = (w1 > w2) ? w1 : w2;
  41.     
  42.     /* calc left-side x as the lesser x of the two rectangles */
  43.  
  44.     w1 = prect1->g_x;
  45.     w2 = prect2->g_x;
  46.     lx = (w1 < w2) ? w1 : w2;
  47.     
  48.     /* calc top y as the lesser y of the two rectangles */
  49.  
  50.     w1 = prect1->g_y;
  51.     w2 = prect2->g_y;
  52.     ty = (w1 < w2) ? w1 : w2;
  53.     
  54.     /* store the calculated rectangle (converting back to GRECT-type w/h) */
  55.  
  56.     prect2->g_x = lx;
  57.     prect2->g_y = ty;
  58.     prect2->g_w = rx - lx;
  59.     prect2->g_h = by - ty;
  60.  
  61.     return;
  62. }
  63.  
  64.  
  65.